import { Component } from 'react';
import bus from '../../util/bus';
import axios from 'axios'
import './MyInterview.css'

export default class MyInterview extends Component {
  constructor(props) {
    super(props);
    const { useremail } = props;
    this.state = {
      useremail: useremail,
      interviews: [

      ],
    }
  }
  render () {
    return (
      <div className="my-interviews">
        <ul>
          {
            this.state.interviews.map(
              (interview, index) => {
                return <li className="interviewItem" key={interview.interviewId}>{interview.interviewId}</li>
              }
            )
          }
        </ul>
      </div>
    )
  }
  componentDidMount () {
    let that = this;

    let url = 'https://qcge2v.fn.thelarkcloud.com/getInterviewByUseremail?useremail=';
    url += that.state.useremail;
    axios.get(url).then((rep) => {
      const interviews = rep.data.result;
      that.setState({ interviews: interviews });
    })

    bus.on('MyInterviewUpdate', () => {
      let url = 'https://qcge2v.fn.thelarkcloud.com/getInterviewByUseremail?useremail=';
      url += that.state.useremail;
      axios.get(url).then((rep) => {
        console.log(rep);
        const interviews = rep.data.result;
        that.setState({ interviews: interviews });
      })
    })
  }
}